import Vue from 'vue'
import Router from 'vue-router'
// 加载主页的路由

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this,location).catch(err => err)
}
// 解决报错
const originalReplace = Router.prototype.replace
// 针对 replace 方法
Router.prototype.replace = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}

Vue.use(Router)
const router = new Router({
  scrollBehavior(to, from, savedPosition) {
    // keep-alive 返回缓存页面后记录浏览位置
    if (savedPosition && to.meta.keepAlive) {
     return savedPosition;
    }
    // 异步滚动操作
    return new Promise((resolve) => {
     setTimeout(() => {
      resolve({ x: 0, y: 0 });
     }, 0);
    });
  },
  routes: [
    // ABB登录页
    {
			path: '/login',
			name: 'login',
			meta: {
				keepAlive:false, //不缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/login')
		}, //登录页
    {
			path: '/main',
			name: 'mainPage',
			meta: {
			  index: 1,
				keepAlive:false, //不缓存
			  showBottomTabBar: true,
			  title: '首页'
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/main')
		}, //登录后的主页
    {path: '/forgotpswd',name: 'forgotpswd',component: () => import(/* webpackChunkName: "Home" */'@/views/forgotpswd'),}, //忘记密码
    {
			path: '/jianhuo',
			name: 'jianhuo',
			meta: {
			  index: 1,
				keepAlive:false, //不缓存
			  showBottomTabBar: true,
			  title: '首页'
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo')
		}, //拣货
    {
			path: '/pandian',
			name: 'pandian',
			meta: {
			  index: 1,
				keepAlive:false, //不缓存
			  showBottomTabBar: true,
			  title: '首页'
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/pandian')
		}, //拣货
    {
			path: '/search',
			name: 'search',
			meta: {
				index: 1,
				keepAlive:false, //不缓存
				showBottomTabBar: true,
				title: '首页'
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/search')
		}, //拣货
    //-- 各种业务的页面
		{
			path: '/shouhuoqidong',
			name: 'shouhuoqidong',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/shouhuo/shouhuoqidong')
		}, //收货启动
		{
			path: '/ywshouhuo_xhr',
			name: 'ywshouhuo_xhr',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/shouhuo/ywshouhuo_xhr')
		}, //收货卸货人
		{
			path: '/ywshouhuo_yhsh',
			name: 'ywshouhuo_yhsh',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/shouhuo/ywshouhuo_yhsh')
		}, //验货收货
		{
			path: '/ywshouhuo_shsj',
			name: 'ywshouhuo_shsj',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/shouhuo/ywshouhuo_shsj')
		}, //收货上架
		{
			path: '/ywshouhuo_shxg',
			name: 'ywshouhuo_shxg',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/shouhuo/ywshouhuo_shxg')
		}, //收货修改
		{
			path: '/zhitongfenhuo',
			name: 'zhitongfenhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/shouhuo/zhitongfenhuo')
		}, //直通分货



		{
			path: '/zhengtuojianhuo',
			name: 'zhengtuojianhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/zhengtuojianhuo')
		}, //整托拣货
		{
			path: '/pintuojianhuo',
			name: 'pintuojianhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/pintuojianhuo')
		}, //整托拣货
    {
			path: '/pintuojianhuo_news',
			name: 'pintuojianhuo_news',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/pintuojianhuo_news')
		}, //整托拣货
		{
			path: '/zhengjianfenbo',
			name: 'zhengjianfenbo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/zhengjianfenbo')
		}, //整件分拨
		{
			path: '/chailinfenbo',
			name: 'chailinfenbo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/chailinfenbo')
		}, //拆零分拨
		{
			path: '/rongqifuhe',
			name: 'rongqifuhe',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/rongqifuhe')
		}, //容器复核
		{
			path: '/dongtaibuhuo',
			name: 'dongtaibuhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/dongtaibuhuo')
		}, //动态补货
		{
			path: '/jingtaibuhuo',
			name: 'jingtaibuhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/jingtaibuhuo')
		}, //静态补货
		{
			path: '/storejh',
			name: 'storejh',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/store/storejh')
		}, //按店拣货
		{
			path: '/storejieshu',
			name: 'storejieshu',
			meta: {
				keepAlive: false, // 已经正确设置为不缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/store/storejieshu')
		}, //按店拣货
		{
			path: '/chailinhuanhuo',
			name: 'chailinhuanhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/chailinhuanhuo')
		}, //拆零还货
		{
			path: '/fuherongqi',
			name: 'fuherongqi',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/fuherongqi')
		}, //复核容器
		{
			path: '/zhengtuojianhuoN',
			name: 'zhengtuojianhuoN',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/zhengtuojianhuoN')
		}, //整托拣货N
		{
			path: '/gaijianhuoshu',
			name: 'gaijianhuoshu',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/gaijianhuoshu')
		}, //改拣货数
    {
			path: '/gaijianhuoshuY',
			name: 'gaijianhuoshuY',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/gaijianhuoshuY')
		}, //改拣货数

		{
			path: '/shouhuoqidongnews',
			name: 'shouhuoqidongnews',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/shouhuoqidongnews')
		}, //收货启动
		{
			path: '/tuopanhunzai',
			name: 'tuopanhunzai',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/tuopanhunzai')
		}, //托盘混载
		{
			path: '/hunzaijiebang',
			name: 'hunzaijiebang',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/hunzaijiebang')
		}, //混载解绑
		{
			path: '/shouhuojiedan',
			name: 'shouhuojiedan',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/shouhuojiedan')
		}, //收货结单
		{
			path: '/quxiaoshouhuo',
			name: 'quxiaoshouhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/quxiaoshouhuo')
		}, //取消收货
		{
			path: '/caigoutuihuo',
			name: 'caigoutuihuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/caigoutuihuo')
		}, //采购退货
		{
			path: '/shouhuochaxun',
			name: 'shouhuochaxun',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/shouhuochaxun')
		}, //收货查询
		{
			path: '/longchejianhuo',
			name: 'longchejianhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/longche/longchejianhuo')
		}, //笼车拣货
		{
			path: '/longchejieshu',
			name: 'longchejieshu',
			meta: {
				keepAlive:false, //不缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/longche/longchejieshu')
		}, //笼车结束
		{
			path: '/newsfuherongqi',
			name: 'newsfuherongqi',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/newsfuherongqi')
		}, //复核容器新
		{
			path: '/jianhuojihuo',
			name: 'jianhuojihuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/jianhuojihuo')
		}, //拣货集货
		{
			path: '/yilingjianhuo',
			name: 'yilingjianhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/yilingjianhuo')
		}, //已领拣货

		{
			path: '/jihuolanshou',
			name: 'jihuolanshou',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/jihuolanshou')
		}, //集货揽收
		{
			path: '/jihuofenfa',
			name: 'jihuofenfa',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/jihuofenfa')
		}, //集货分发
		{
			path: '/zhitongjianhuo',
			name: 'zhitongjianhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/zhitongjianhuo')
		}, //直通拣货


		{
			path: '/zhuangche',
			name: 'zhuangche',

			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/zhuangche/zhuangche')
		}, //装车
		{
			path: '/zhuangcheSon',
			name: 'zhuangcheSon',
			meta: {
				keepAlive:false, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/zhuangche/zhuangcheSon')
		}, //装车列表
		{
			path: '/zhuangchepeisong',
			name: 'zhuangchepeisong',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/zhuangche/zhuangchepeisong')
		}, //装车配送
		{
			path: '/kuneiyidong',
			name: 'kuneiyidong',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/kuneiyidong')
		}, //库内移动
		{
			path: '/yiweishangjia',
			name: 'yiweishangjia',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/yiweishangjia')
		}, //移位上架
		{
			path: '/yiweixiajia',
			name: 'yiweixiajia',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/yiweixiajia')
		}, //移位下架
		{
			path: '/yikuyichu',
			name: 'yikuyichu',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/yikuyichu')
		}, //移库移出
		{
			path: '/yikushouhuo',
			name: 'yikushouhuo',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/yikushouhuo')
		}, //移库收货
		{
			path: '/meiridongpan',
			name: 'meiridongpan',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/chuhuo/meiridongpan')
		}, //每日动盘



		{
			path: '/gongju',
			name: 'gongju',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/gongju')
		}, //工具选择
		{
			path: '/searchSystem',
			name: 'searchSystem',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/searchSystem')
		}, //查询系统
		{
			path: '/shangjiafenpei',
			name:'shangjiafenpei',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/shangjiafenpei')
		}, //上架分配
		{
			path: '/duobaozhuangpin',
			name:'duobaozhuangpin',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/duobaozhuangpin')
		},//多包装品
		{
			path: '/duoriweipei',
			name:'duoriweipei',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/duoriweipei')
		},//多日未配
		{
			path: '/cangweirizhi',
			name:'cangweirizhi',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/cangweirizhi')
		},//仓位日志
		{
			path: '/kucunrizhi',
			name:'kucunrizhi',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/kucunrizhi')
		},//库存日志
		{
			path: '/shangpinshuxing',
			name:'shangpinshuxing',
			meta: {
				keepAlive:true, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/shangpinshuxing')
		},//商品属性

		{
			path: '/renwugaikuang',
			name:'renwugaikuang',
			meta: {
				keepAlive:false, //缓存
			},
			component: () => import(/* webpackChunkName: "Home" */'@/views/system/renwugaikuang')
		},//任务挂靠

    {
      path: '/gaifenboshuY',
      name: 'gaifenboshuY',
      meta: {
        keepAlive: true, // 缓存
      },
      component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/gaifenboshuY')
    }, //改分拨数
    {
      path: '/bangdinglongche',
      name: 'bangdinglongche',
      meta: {
        keepAlive: true, // 缓存
      },
      component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/longche/bangdinglongche')
    }, //绑定笼车
    {
      path: '/huishoulongche',
      name: 'huishoulongche',
      meta: {
        keepAlive: true, // 缓存
      },
      component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/longche/huishoulongche')
    }, //回收笼车
    // fenbochaxun
    {
      path: '/fenbochaxun',
      name: 'fenbochaxun',
      meta: {
        keepAlive:  false, // 缓存
      },
      component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/fenbochaxun')
    }, //分拨查询
    {
      path: '/bocistore',
      name: 'bocistore',
      meta: {
        keepAlive:  true, // 缓存
      },
      component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/bocistore')
    }, //波次门店线路
    {
      path: '/bocifenbocx',
      name: 'bocifenbocx',
      meta: {
        keepAlive:  true, // 缓存
      },
      component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/bocifenbocx')
    }, //波次分拨查询
    {
      path: '/fuherongqiDong',
      name: 'fuherongqiDong',
      meta: {
        keepAlive:  true, // 缓存
      },
      component: () => import(/* webpackChunkName: "Home" */'@/views/jianhuo/fuherongqiDong')
    }, //复核商品(冻)
    // 路由跳转
    {path:'/*',redirect:'/login'},
  ],
});

//导航守卫 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// to 将要访问的路径
// from 代表从哪个路径跳转而来
// next 是一个函数，表示放行
// next()  放行    next('/login')  强制跳转
// router.beforeEach((to, from, next) => {
//   //debugger;
//   console.log('-------------to=>',to,'--------------from=>',from,'-----------------------next=>',next);
//   //进行自动登录的处理---start----
//   let token = localStorage.getItem('Authorization'); var t = window.GWO();
//   //进行自动登录的处理---end----
//   var ls_to_path = to.path,ls_from_path = from.path;
//   //2024-04-25 增加 权限判断
//   var ls_operatorid;
//   if(token > '' && t && t.gUSER && t.gUSER.operatorid && t.gUSER.operatorid > '')
//   {
//     try{
//       ls_operatorid = t.gUSER.operatorid;
//       if(ls_operatorid != null && ( ls_operatorid > '' ) ){ //|| ls_ehrole.indexOf('女工主任') >=0
//         //有权限
//       }else{
//         ls_to_path = '/denynoright'; //无权限
//       }
//     }catch(ee){
//       ls_to_path = '/denynoright';
//     }
//   }else{
//     ls_to_path = '/login'; //没有登录
//   }
//   //
//   console.log('ls_to_path:'+ls_to_path+',ls_from_path:'+ls_from_path);
//   if(ls_to_path === '/'){
//     if( window.GWO().autologinrouter > '' ){
//       if(window.GWO().autologinrouter.substr(0,1)=='/'){
//         next(window.GWO().autologinrouter);
//       }else{
//         next({name: window.GWO().autologinrouter});
//       }
//       return;
//     }else{
//       if(ls_operatorid > ''){
//         ls_to_path = '/f1main'; //已经登陆过的,直接到Home
//       }else{
//         ls_to_path = '/login'; //没有
//       }
//     }
//   }

//   //
//   if ( ['/login','/forgotpswd' ].indexOf(ls_to_path) >= 0 ) { //登录页 和 找回密码页
//     // ms ad 登陆失效好,不要出现,用户密码窗口, 上面已经判断了
//     if(ls_to_path > '' && (ls_to_path == to.path)){
//       next();
//     }else{
//       next(ls_to_path);
//     }
//   }else if (ls_to_path != null &&  ['/login'].indexOf(ls_to_path) >= 0 ) {
//     //无条件显示 //用户协议 和 隐私政策允许不登录就显示
//     if(ls_to_path > '' && (ls_to_path == to.path)){
//       next();
//     }else{
//       next(ls_to_path);
//     }
//   } else { //其他页面

//     if(ls_to_path > '' && (ls_to_path == to.path)){

//       next();
//     }else{

//       next(ls_to_path);

//     }
//   }
// });

router.afterEach((to,from,next) => {
  window.scrollTo(0,0);
});

// 添加清除缓存的方法
export function clearRouterCache() {
  // 获取所有带有 keepAlive 的路由
  const routes = router.options.routes;
  routes.forEach(route => {
    if (route.meta && route.meta.keepAlive) {
      route.meta.keepAlive = false; // 禁用缓存
    }
  });
}

export default router;
//查找筛选的目录设置 ./src/main.js,./src/store/index.js,./src/router/index.js,./src/pagesv2/*/*.vue,./src/pagesv2/*.vue


